package com.xjust.controller;

import com.xjust.pojo.Result;
import com.xjust.service.impl.CourseServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/courses")
@Api(tags = "课程管理相关接口")  // Swagger 注解，描述控制器的整体功能
@CrossOrigin
public class CourseController {
    @Autowired
    CourseServiceImpl courseService;

    @GetMapping("getAllCourse")
    @ApiOperation(value = "获取所有课程信息", notes = "返回系统中所有课程的列表")  // 描述该API的功能
    public Result getAllCourse(){
        List<Map<String,Object>> list = courseService.getAllCourse();
        return Result.success(list);
    }

    @GetMapping("/getClassBycourse")
    @ApiOperation(value = "根据课程ID查询班级信息", notes = "根据提供的课程ID返回相应班级的详细信息")
    public Result getClassBycourse(Integer courseId){
        List<Map<String,Object>> list = courseService.getClassBycourse(courseId);
        return Result.success(list);
    }

    @PostMapping("/insertCourseSelection")
    @ApiOperation(value = "提交选课信息", notes = "根据提供的课程和班级信息提交选课请求")
    public Result insertCourseSelection(@RequestBody Map<String,Object> courseInfo){
        courseService.insertCourseSelection(courseInfo);
        return Result.success();
    }

    @GetMapping("/getCourseSelect")
    @ApiOperation(value = "根据学生ID查询选课信息", notes = "根据学生ID查询并返回选课信息列表")
    public Result getCourseSelect(){
        ArrayList<Integer> courseSelect = courseService.getCourseSelect();
        return Result.success(courseSelect);
    }
}